package cn.skyquant.quant4j.jforex.strategy;

import com.dukascopy.api.*;

public class Test1 implements IStrategy ,ILoadingReportPositionListener,LoadingProgressListener{

    @Configurable("时间间隔")
    public Period period = Period.FIVE_MINS;

    @Configurable("货币")
    public Instrument instrument = Instrument.EURUSD;


    protected IEngine engine;
    protected IConsole console;
    protected IHistory history;
    protected IContext context;
    protected IIndicators indicators;
    protected IUserInterface userInterface;
    protected IDataService dataService;
    protected IAccount account;
    protected JFUtils jfUtils;
    @Override
    public void onStart(IContext context) throws JFException {
        this.engine = context.getEngine();
        this.console = context.getConsole();
        this.history = context.getHistory();
        this.context = context;
        this.indicators = context.getIndicators();
        this.userInterface = context.getUserInterface();
        this.dataService = context.getDataService();
        this.jfUtils = context.getUtils();
        this.account = context.getAccount();



//        Map<String,Object> map = context.getDataService().getServerProperties();
//        map.forEach((k,v)->console.getOut().println("K="+k+",v="+v));

//        List<IReportPosition> reportPositionList = context.getReportService().getClosedPositions(0,context.getTime());
//
//        for(IReportPosition rs:reportPositionList){
//            console.getOut().println(rs);
//        }
//
//        context.getReportService().readClosedPositions(0,context.getTime(),this,this);
        console.getOut().println(context.getFilesDir().getPath());

        String title = userInterface.getMainFrame().getTitle();
        console.getOut().println("title:"+title);
    }

    @Override
    public void onTick(Instrument instrument, ITick tick) throws JFException {
    }

    @Override
    public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {

    }

    @Override
    public void onMessage(IMessage message) throws JFException {
        console.getOut().println(message);
    }

    @Override
    public void onAccount(IAccount account) throws JFException {

    }

    @Override
    public void onStop() throws JFException {
    }

    @Override
    public void newReportPosition(IReportPosition reportPosition) {
        console.getOut().println(reportPosition);
    }

    @Override
    public void dataLoaded(long start, long end, long currentPosition, String information) {
        console.getOut().println("dataLoaded="+start+",end="+end+",currentPosition="+currentPosition+",information="+information);
    }

    @Override
    public void loadingFinished(boolean allDataLoaded, long start, long end, long currentPosition) {
        console.getOut().println("allDataLoaded="+allDataLoaded+",start="+start+",end="+end+",currentPosition="+currentPosition);
    }

    @Override
    public boolean stopJob() {
        return true;
    }

}
